package com.fr.lintcode;

import org.junit.Test;

/**
*作者：furong
*日期：2016年12月26日
*时间：下午10:46:26
*/
public class Q56 {
	/**
     * @param numbers: An array of Integer
     * @param target: target = numbers[index1] + numbers[index2]
     * @return: [index1, index2] (index1 < index2)
     */
    public int[] twoSum(int[] numbers, int target) {
        if (numbers == null || numbers.length <= 0) {
            return null;
        }
        int[] rs = new int[2];
        for (int i = 0; i < numbers.length; i++) {
            for (int j = i + 1; j < numbers.length; j++) {
                if (numbers[i] + numbers[j] == target) {
                    rs[0] = i;
                    rs[1] = j;
                    return rs;
                }
            }
        }
        return rs;
    }

    @Test
    public void testA() {
        int[] numbers = { 2, 7, 11, 15 };
        int target = 9;
        System.out.println(twoSum(numbers, target));
    }

}
